// pages/classify/classify.js
import { GetclassFyList, GetclassFyListT,addCart } from "../../network/api/classify/index"

Page({
		data: {
			classFyLeftList: [],
			classFyRightList: [],
			id: 233216,
			active: 0,
			num:''
		},
		click (e) {
			let categoryid = e.currentTarget.dataset.id
			this.setData({
				active: e.currentTarget.dataset.index
			})
			GetclassFyListT(categoryid).then(res => {
				let arr = res.data.filter(item=>{
					return item.categoryId === categoryid

				})
				console.log(arr)
				this.setData({
					classFyRightList: arr.reverse()
				})
			})
		},
		tiao(e){
			
			let idd=e.currentTarget.dataset.item.categoryId
			console.log(idd);
			wx.navigateTo({
				url: '/pages/detail/detail?id='+e.target.dataset.id
			})
		},
		addShop(e){
			console.log(e.target.dataset);
		let {goodsid, number} = e.target.dataset
		let goodsId = goodsid
		let token = wx.getStorageSync('token')
		addCart({goodsId,number,token}).then(res=>{
				console.log(res);
				wx.showToast({
					title: '加入成功',
					icon:'success',
					mask:true
				})
			})
        },
		onLoad: function (options) {
			console.log(options);
			this.setData({
				active:options.id
			})
			if (options.id) {
				GetclassFyListT(options.id).then(res => {
			let arr = res.data.filter(item=>{
						return item.categoryId===options.id
					})
					this.setData({
						classFyRightList: arr.reverse()
					})
				})
			} else {
				GetclassFyListT(233226).then(res => {
					let arr = res.data.filter(item=>{
						return item.categoryId===233226
					})
					this.setData({
						classFyRightList: arr.reverse(),
						classObj: res.data
					})
				})
			}
			GetclassFyList().then(res => {
				this.setData({
					classFyLeftList: res.data,
				})
			})
			
		}
	}
)